#include "hedcontroller.h"
#include "euleroperator.h"
#include <iostream>


HEDController::HEDController()
{
	//eulerop.setModel(....);
}

void 
HEDController::doAddPoint(double x, double y, double z)
{
  // always when adding a vertex into the topological data structure,
  // performs the following geometric checks:
  // 1: checks if the model already contains a vertex
  // 2: checks if the coordinate is the same of an existing vertex
  // 3: checks if the coordinate lies on an curve or on an region
  if( geomChecker.hasAnyVertex(model) ) // substitute it with cheaper test
  {
    if( geomChecker.hasVertexWithGivenCoords(model,x,y,z) )
    {
      std::cout << ".WARNING: There is already a vertex with the same coordinate!" << std::endl;
    }
  }
  else
  {
    eulerop.mvfs(model,1, 1, 1, x, y, z);
  }
}

void 
HEDController::doAddCurve(double x1, double y1, double z1, double x2, double y2, double z2)
{
  // always when adding a curve into the topological data structure,
  // performs the following geometric checks:
  // 1: checks if the model already contains a vertex
  // 1: checks if the curve intersects a vertex of the model
  // 2: checks if the curve intersects another curve of the model
  // 3: checks if one end point of the curve belong to vertex of the model
  // 4: checks if both end points of the curve belong to vertexes of the model
  if( geomChecker.hasAnyVertex(model) ) // substitute it with cheaper test
  {
    int n = 0;
    double* interPts = NULL;
    double curvePts[6];
    curvePts[0] = x1;    curvePts[1] = y1;    curvePts[2] = z1;
    curvePts[3] = x2;    curvePts[4] = y2;    curvePts[5] = z2;
    geomChecker.intersectsVertex(model,curvePts,n,interPts);
    geomChecker.intersectsCurves(model,curvePts,n,interPts);


    bool hasP1 = geomChecker.hasVertexWithGivenCoords(model,x1,y1,z1);
    bool hasP2 = geomChecker.hasVertexWithGivenCoords(model,x2,y2,z2);
    if( hasP1 && hasP2 )
    {
       //eulerop.mef(...);
    }
    else if( hasP1 || hasP2 )
    {
      eulerop.mev(model, 1, 1, 1, 1, 1, 1, 2, x2, y2, z2);
    }
    else
    {
    }
  }
  else
  {
    eulerop.mvfs(model,1, 1, 1, x1, y1, z1);
    eulerop.mev(model, 1, 1, 1, 1, 1, 1, 2, x2, y2, z2);
  }

}

void HEDController::doManipulate()
{
	std::cout << "HEDController::doManipulate nao implementado.\n";
}
void HEDController::doCreate()
{
	std::cout << "HEDController::doCreate nao implementado.\n";
}
void HEDController::doEdit()
{
	std::cout << "HEDController::doEdit nao implementado.\n";
}
void HEDController::doDelete()
{
	std::cout << "HEDController::doDelete nao implementado.\n";
}
void HEDController::doSave()
{
	std::cout << "HEDController::doSave nao implementado.\n";
}
void HEDController::doManage()
{
	std::cout << "HEDController::doManage nao implementado.\n";
}
void HEDController::doExit()
{
	std::cout << "HEDController::doExit nao implementado.\n";
}